﻿using System;
using System.Data;
using System.Data.SqlClient;
using SqlOperate;
using System.Configuration;
using nspLable.Function;

///**************************************************
///<summary>
///Depiction：此类是企业发布招聘信息，以及对招聘信息的增加，删除，修改，查询
///Create Date：2009-8-31
///</summary>
///**************************************************
namespace nspJob
{
    public class Rjob : IJob
    {
        #region R_job 成员
        ///**************************************************
        /// <summary>
        /// depiction：该方法用于对职位的添加
        /// </summary>
        /// <param name="tb"><职位的实体对象></param>
        /// <returns>
        ///方法的返回值表示 是否更新成功，如果成功返回1 否则返回0
        /// </returns>
        ///**************************************************
        public int Insert(TJob tb)
        {
            SqlParameter[] commandParameters = new SqlParameter[]
            {                
					new SqlParameter("@UserID",tb.UserID),
					new SqlParameter("@TypeID", tb.TypeID),
					new SqlParameter("@Position", tb.Position),
					new SqlParameter("@Count",tb.JobCount),
					new SqlParameter("@Degree",tb.Degree),
					new SqlParameter("@AgeRequest",tb.AgeRequest),
					new SqlParameter("@Experience ", tb.Experience),
					new SqlParameter("@WorkTemper", tb.WorkTemper),
					new SqlParameter("@Address", tb.Address),
					new SqlParameter("@SalaryLevel",tb.SalaryLevel),
					new SqlParameter("@Sex", tb.Sex),
					new SqlParameter("@EnglishLevel", tb.EnglishLevel),
					new SqlParameter("@ComputerLevel",tb.ComputerLevel),
					new SqlParameter("@verify", tb.verify),
					new SqlParameter("@EndDate", tb.EndDate),
					new SqlParameter("@isRecommend", tb.isRecommend)
					
             };
            return SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "SP_C_job_Add", commandParameters);
        }

        ///**************************************************
        /// <summary>
        /// depiction：该方法用于对职位的修改
        /// </summary>
        /// <param name="tb"><职位的实体对象></param>
        /// <returns>
        ///方法的返回值表示 是否更新成功，如果成功返回1 否则返回0
        /// </returns>
        ///**************************************************
        public int Update(TJob tb)
        {
            SqlParameter[] commandParameters = new SqlParameter[]
            {   
                    new SqlParameter("@ID", tb.ID),
					new SqlParameter("@TypeID", tb.TypeID),
					new SqlParameter("@Position", tb.Position),
					new SqlParameter("@Count",tb.JobCount),
					new SqlParameter("@Degree",tb.Degree),
					new SqlParameter("@AgeRequest",tb.AgeRequest),
					new SqlParameter("@Experience ", tb.Experience),
					new SqlParameter("@WorkTemper", tb.WorkTemper),
					new SqlParameter("@Address", tb.Address),
					new SqlParameter("@SalaryLevel",tb.SalaryLevel),
					new SqlParameter("@Sex", tb.Sex),
					new SqlParameter("@EnglishLevel", tb.EnglishLevel),
					new SqlParameter("@ComputerLevel",tb.ComputerLevel),
					new SqlParameter("@EndDate", tb.EndDate)
	        };
            return SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "SP_C_job_update", commandParameters);
        }
        ///**************************************************
        /// <summary>
        /// depiction：该方法用于对职位的删除
        /// </summary>
        /// <param name="tb"><职位的实体对象></param>
        /// <returns>
        ///方法的返回值表示 是否更新成功，如果成功返回1 否则返回0
        /// </returns>

        ///Create Date：2009-8-31
        ///**************************************************
        public int Delete(string table, int ID, string typeid)
        {
            SqlParameter[] param = new SqlParameter[] 
            {
                new SqlParameter("@strwhere", "where " +typeid+" in (" + ID + ")"), 
                new SqlParameter("@strTableName", table) 
            };
            return SqlHelper.DeleteByWhere("SP_DeleteByWhere", param);
        }
        ///**************************************************
        /// <summary>
        /// depiction：该方法用于根据条件查询符合条件的职位
        /// </summary>
        /// <param name="tb"><职位的实体对象></param>
        /// <returns>
        ///
        /// </returns>
        ///Create Date：2009-8-31
        ///**************************************************
        public DataTable GetDataTableByWhere(int ParamID)
        {
            SqlParameter[] param = new SqlParameter[] 
            { 
                new SqlParameter("@strSelect","*"),
                new SqlParameter("@strwhere","where C_Job.ID="+ParamID),
                new SqlParameter("@strtableName", "C_Job")
            };
            return SqlHelper.ExecuteTable(CommandType.StoredProcedure, "SP_SelectByWhere", param);
        }
        ///**************************************************
        /// <summary>
        /// depiction：该方法用于根据条件查询符合条件的职位
        /// </summary>
        /// <param name="tb"><职位的实体对象></param>
        /// <returns>
        ///方
        /// </returns>
        ///Create Date：2009-8-31
        ///**************************************************
        public DataTable GetDataTable(String table, String ParamID)
        {
            SqlParameter[] param = new SqlParameter[] 
            { 
                new SqlParameter("@strSelect","*"),
                new SqlParameter("@strwhere","where ID='"+ParamID+"'"),
                new SqlParameter("@strtableName", table)
            };
            return SqlHelper.ExecuteTable(CommandType.StoredProcedure, "SP_SelectByWhere", param);
        }

        ///**************************************************
        /// <summary>
        /// depiction：该方法用于根据表名查询数据
        /// </summary>
        /// <param name="<参数名称>"><参数说明></param>
        /// <returns>
        ///<对方法返回值的说明，该说明必须明确说明返回的值代表什么含义>
        /// </returns>
        ///Create Date：2009-9-4
        ///**************************************************
        public DataTable GetDataType(string table)
        {
            SqlParameter[] param = new SqlParameter[] 
            { 
                new SqlParameter("@strSelect","*"),
                new SqlParameter("@strtableName", table)
            };
            return SqlHelper.ExecuteTable(CommandType.StoredProcedure, "SP_SelectByWhere", param);
        }
        public DataTable GetDataType(string table,int userid)
        {
            SqlParameter[] param = new SqlParameter[] 
            { 
                new SqlParameter("@strSelect","*"),
                new SqlParameter("@strwhere","where UserId="+userid),
                new SqlParameter("@strtableName", table)
            };
            return SqlHelper.ExecuteTable(CommandType.StoredProcedure, "SP_SelectByWhere", param);
        }
        ///**************************************************
        /// <summary>
        /// depiction：判断企业发布职位名称是否重复
        /// </summary>
        /// <param name="<参数名称>"><参数说明></param>
        /// <returns>
        ///<对方法返回值的说明，该说明必须明确说明返回的值代表什么含义>
        /// </returns>
        ///Create Date：2009-9-4
        ///**************************************************
        public bool GetDataPositionExists(string position, int userid)
        {
            int num = 0;
            String sql = "select count(*)  from C_Job where Position='" + position + "' and  UserID=" + userid + "";
            SqlConnection conn = new SqlConnection(SqlHelper.ConnectionString);
            conn.Open();
            SqlCommand cmmd = new SqlCommand(sql, conn);
            num = Convert.ToInt32(cmmd.ExecuteScalar());
            conn.Close();
            if (num > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        //根据职位ID获取职位发布状态
        public bool GetStateIsEnable(int id)
        {
            SqlParameter[] param = new SqlParameter[] 
            { 
                new SqlParameter("@strSelect","*"),
                new SqlParameter("@strWhere", "where ID=" + id), 
                new SqlParameter("@strTableName", "U_Resume")
            };
            bool flag = false;
            using (SqlDataReader reader = SqlHelper.ExecuteReader(CommandType.StoredProcedure, "SP_SelectByWhere", param))
            {
                if (reader.Read())
                    flag =Convert.ToBoolean(reader["isEnable"]);
            }
            return flag;
        }
        public string lowerType(string strTypeLink,int type)
        {
            try
            {
                
                DataTable TypeData = new DataTable();
                string strType = "";
                if (type == 1)
                {
                    TypeData = SqlHelper.ExecuteSqlQuery("select distinct a.ID,a.TypeName,a.Fid,count(b.ID) as jcount from C_JobType as a  left join C_Job as b on (a.ID=b.TypeID or (select c.FID from C_JobType as c where c.ID=b.TypeID )=a.ID ) and (datediff(hh,b.EndDate,getdate())<0) AND b.Verify=1  where a.FID=" + strTypeLink + "  group by a.ID,a.TypeName,a.Fid");
                    foreach (DataRow dr in TypeData.Rows)
                    {
                        strType += "<span><a title=\"\" class=\"l_666\" href=\"" + Base.BasePage.Config.WebURL + "job/JobTrade" + Base.BasePage.Config.Rewrite + "?type=" + type + "&id=" + dr["ID"] + "\">" + Function.GetString(dr["TypeName"].ToString(), 5) + "(" + dr["jcount"] + ")</a></span>";
                    }
                }
                if (type == 2)
                {
                    TypeData = SqlHelper.ExecuteSqlQuery("select distinct a.ID,a.TypeName,a.Fid,count(b.ID) as jcount from C_JobType as a  left join U_Resume as b on (a.ID=b.TalentType or (select c.FID from C_JobType as c where c.ID=b.TalentType )=a.ID ) AND b.Verify=1  where a.FID=" + strTypeLink + "  group by a.ID,a.TypeName,a.Fid");
                    foreach (DataRow dr in TypeData.Rows)
                    {
                        strType += "<span><a title=\"\" class=\"l_666\" href=\"" + Base.BasePage.Config.WebURL + "job/JobTrade" + Base.BasePage.Config.Rewrite + "?type=" + type + "&id=" + dr["ID"] + "\">" + Function.GetString(dr["TypeName"].ToString(), 5) + "(" + dr["jcount"] + ")</a></span>";
                    }
                    
                }
                return strType;
            }
            catch (Exception ex)
            {
                return "";
            }
        }
        public string TypeLink(string strTypeLink)
        {
            if (strTypeLink[strTypeLink.Length - 1] == ',')
            {
                strTypeLink = strTypeLink.Substring(0, strTypeLink.Length - 1);
            }
            try
            {
                DataTable TypeData = new DataTable();
                TypeData = SqlHelper.ExecuteSqlQuery(" SELECT [TypeName] ,ID FROM C_JobType where ID=(select FID from C_JobType where ID=" + strTypeLink + "  )  or ID=" + strTypeLink + " order by ID  ");
                string strType = "";
                string str = "<a href=\"jobtrade-";

                if (TypeData.Rows.Count > 0)
                {
                    for (int i = 0; i < TypeData.Rows.Count; i++)
                    {
                        strType += " > " + str;
                        strType += TypeData.Rows[i]["id"].ToString();
                        strType += Base.BasePage.Config.Rewrite + "\">";
                        strType += TypeData.Rows[i]["TypeName"].ToString();
                        strType += "</a>";
                    }
                }
                return strType;
            }
            catch (Exception ex)
            {
                return "";
            }
        }
        public DataTable GetJoblist(string strSelect, string strWhere)
        {
            string strsql = strSelect;
            if (strWhere != "")
            {
                strsql += " where " + strWhere;
            }
            DataTable dt = SqlHelper.ExecuteSqlQuery(strsql);
            return dt;
        }
        public DataTable GetJobType()
        {
            string strsql = " select * from  dbo.C_JobType where FID=0 ";
            DataTable dt = SqlHelper.ExecuteSqlQuery(strsql);
            return dt;
        }
        public DataTable GetJobTypeByFid(int id)
        {
            string strsql = " select * from  dbo.C_JobType where FID= " + id;
            DataTable dt = SqlHelper.ExecuteSqlQuery(strsql);
            return dt;
        }
        public DataTable GetcompanyCount(string strWhere)
        {
            string str = " select * from U_UserInfo";
            if (strWhere != "")
            {
                str += " where " + strWhere;
            }
            DataTable dt = SqlHelper.ExecuteSqlQuery(str);
            return dt;
        }

        /// <summary>
        /// 根据ID得到供应每一条信息
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public TJob GateItem(int ID)
        {
            SqlParameter[] param = new SqlParameter[] 
            { 
                new SqlParameter("@strWhere", "where ID=" +Convert.ToInt32( ID)), 
                new SqlParameter("@strTableName", "C_Job"), 
                new SqlParameter("@strOrder", "") 
            };
            TJob info = new TJob();
            using (SqlDataReader reader = SqlHelper.ExecuteReader(CommandType.StoredProcedure, "SP_SelectByWhere", param))
            {
                if (!reader.Read())
                {
                    return info;
                }
                if (reader["ID"].ToString() != "")
                {
                    info.ID = Convert.ToInt32(reader["ID"].ToString());
                }
                if (reader["UserID"].ToString() != "")
                {
                    info.UserID = Convert.ToInt32(reader["UserID"].ToString());
                }
                if (reader["TypeID"].ToString() != "")
                {
                    info.TypeID = Convert.ToInt32(reader["TypeID"].ToString());
                }

                info.Position = reader["Position"].ToString();

                if (reader["Count"].ToString() != "")
                {
                    info.JobCount = Convert.ToInt32(reader["Count"].ToString());
                }


                info.Degree = reader["Degree"].ToString();
                info.AgeRequest = reader["AgeRequest"].ToString();
                info.Experience = (reader["Experience"].ToString());
                info.WorkTemper = reader["WorkTemper"].ToString();
                info.Address = reader["Address"].ToString();
                info.SalaryLevel = reader["SalaryLevel"].ToString();
                info.Sex = reader["Sex"].ToString();
                info.EnglishLevel = reader["EnglishLevel"].ToString();
                info.ComputerLevel = reader["ComputerLevel"].ToString();
                info.RecrtEHistory = reader["Experience"].ToString();
                if (reader["verify"].ToString() != "")
                {
                    info.verify = Convert.ToInt32(reader["verify"].ToString());
                }
                if (reader["EndDate"].ToString() != "")
                {
                    info.EndDate = Convert.ToDateTime(reader["EndDate"].ToString());
                }
                if (reader["isRecommend"].ToString() != "")
                {
                    info.isRecommend = Convert.ToBoolean(reader["isRecommend"].ToString());
                }
                if (reader["AddDate"].ToString() != "")
                {
                    info.AddDate = Convert.ToDateTime(reader["AddDate"].ToString());
                }
            }

            return info;
        }
        #endregion


    }


}
